package com.example.admin.SQLite.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.example.admin.SQLite.BaoMing;
import com.example.admin.SQLite.Complaint;
import com.example.admin.SQLite.SqLiteOpenHelper;

import java.util.ArrayList;

import static com.example.admin.SQLite.SqLiteOpenHelper.BAOMING;
import static com.example.admin.SQLite.SqLiteOpenHelper.FEIYONG;

public class BaoMingDao {
    SqLiteOpenHelper dbHelper;
    private static final String KEY_ID = "id";

    public BaoMingDao(Context context) {
        dbHelper = new SqLiteOpenHelper(context);
    }

    public void DeleteContacts(int id) {
        SQLiteDatabase database = dbHelper.getSqlite();
        database.delete(BAOMING, KEY_ID + " = ? ", new String[]{String.valueOf(id)});
    }
    public long addData(BaoMing bean) {
        SQLiteDatabase db = dbHelper.getSqlite();
        ContentValues values = new ContentValues();
        values.put("title", bean.title);
        values.put("content", bean.content);
        values.put("CreateData", bean.CreateData);
        values.put("Num", bean.Num);
        values.put("imgPath", bean.imgPath);
        long id = db.insert(BAOMING, null, values);
        Log.e("的收费收费的方式", "addData: " + id);
        return id;
    }

    public ArrayList<BaoMing> FindWhereData() {
        SQLiteDatabase db = dbHelper.getSqlite();
        Cursor cursor = db.rawQuery("SELECT * FROM " + BAOMING, null);
        ArrayList<BaoMing> arrContacts = new ArrayList<>();

        while (cursor.moveToNext()) {
            BaoMing model = new BaoMing();
            model.id = cursor.getInt(0);
            model.title = cursor.getString(1);
            model.content = cursor.getString(2);
            model.CreateData = cursor.getString(3);
            model.Num = cursor.getString(4);
            model.imgPath = cursor.getString(5);

            arrContacts.add(model);

        }
        return arrContacts;
    }
    public void updateComs(int id, String str) {

        SQLiteDatabase database = dbHelper.getSqlite();

        ContentValues cv = new ContentValues();
        cv.put("Num", str);

        database.update(BAOMING, cv, KEY_ID + " = " + id, null);
    }
}
